package updown.domain;

import lombok.Builder;
import lombok.Data;
import updown.constant.GeneralConstant;

/**
 * <p>Title: updown.domain </p>
 * <p>Description:updown: -  </p>
 *
 * @Author:jiangkaixin
 * @Date:2022/1/5
 * @Version: 1.0
 */
@Data
@Builder
public class DownUpRetry {
    private ServerHost serverHost;
    private String currentInstanceId;
    private String serviceName;
    @Builder.Default
    private Integer killScriptTryTimes = 1;
    /** kill15 重启脚本 重试间隔 */
    @Builder.Default
    private Integer killScriptTryPeriodSec = 5;

    /** 检查是否 cancel 成功 */
    @Builder.Default
    private Integer checkCancelTryTimes = 1;
    /** 检查是否 cancel 成功 重试间隔 */
    @Builder.Default
    private Integer checkCancelPeriodSec = 10;
    /** Status=DOWN 请求 */
    @Builder.Default
    private Integer downRequestTryTimes = 1;
    /** Status=DOWN 请求 重试间隔*/
    @Builder.Default
    private Integer downRequestPeriodSec = 5;
    /** 重启脚本 */
    @Builder.Default
    private Integer restartScriptTryTimes = 1;
    /** 重启脚本 重试间隔*/
    @Builder.Default
    private Integer restartScriptPeriodSec = 5;
    /** 重启注册到eureka */
    @Builder.Default
    private Integer reRegisterTryTimes = 1;
    /** 重启注册到eureka 重试间隔*/
    @Builder.Default
    private Integer reRegisterPeriodSec = 20;
    /** 重新注册本地缓存更新 检查 */
    @Builder.Default
    private Integer localCheckTryTimes = 1;
    /** 重新注册本地缓存更新 重试间隔*/
    @Builder.Default
    private Integer localCheckPeriodSec = 20;


    public Integer getRetryTimes(String type){
        if (GeneralConstant.RETRY_TYPE_KILL15.equals(type)){
            return killScriptTryTimes;
        }else if (GeneralConstant.RETRY_TYPE_CHECK_CANCEL.equals(type)){
            return checkCancelTryTimes;
        }else if(GeneralConstant.RETRY_TYPE_SEND_DOWN.equals(type)){
           return downRequestTryTimes;
        }else if (GeneralConstant.RETRY_TYPE_RESTART.equals(type)) {
            return restartScriptTryTimes;
        }else if(GeneralConstant.RETRY_TYPE_RE_REGISTER_EUREKA.equals(type)){
            return reRegisterTryTimes;
        }else if(GeneralConstant.RETRY_TYPE_CHECK_LOCAL.equals(type)){
            return localCheckTryTimes;
        }
        return 0;
    }

    public Integer getRetryPeriod(String type){
        if (GeneralConstant.RETRY_TYPE_KILL15.equals(type)){
            return killScriptTryPeriodSec;
        }else if (GeneralConstant.RETRY_TYPE_CHECK_CANCEL.equals(type)){
            return checkCancelPeriodSec;
        }else if(GeneralConstant.RETRY_TYPE_SEND_DOWN.equals(type)){
            return downRequestPeriodSec;
        }else if (GeneralConstant.RETRY_TYPE_RESTART.equals(type)) {
            return restartScriptPeriodSec;
        }else if(GeneralConstant.RETRY_TYPE_RE_REGISTER_EUREKA.equals(type)){
            return reRegisterPeriodSec;
        }else if(GeneralConstant.RETRY_TYPE_CHECK_LOCAL.equals(type)){
            return localCheckPeriodSec;
        }
        return 10;
    }
}
